import getEnvConfig from "./envconfig"

// 获取环境配置
const envConfig = getEnvConfig()

// 获取根URL
export function getBaseUrl() {
    console.log('envConfig.apiBaseUrl===' + envConfig.apiBaseUrl)
    return envConfig.apiBaseUrl
}

// 登录请求API
export function getLoginUrl() {
    if (envConfig.env === 'mock') {
        return {
            url: '/authorizations',
            method: 'GET'
        }
    } else {
        return {
            url: '/authorizations',
            method: 'POST'
        }
    }
}

// 获取用户信息API
export function getProfileUrl() {
    if (envConfig.env === 'mock') {
        return {
            url: '/profile',
            method: 'GET'
        }
    } else {
        return {
            url: '/user/profile',
            method: 'GET'
        }
    }
}

// 获取频道列表API
export function getChannelUrl() {
    if (envConfig.env === 'mock') {
        return {
            url: '/channels',
            method: 'GET'
        }
    } else {
        return {
            url: '/channels',
            method: 'GET'
        }
    }
}

// 获取文章列表API
export function getArticlesUrl() {
    if (envConfig.env === 'mock') {
        return {
            url: '/articles',
            method: 'GET'
        }
    } else {
        return {
            url: '/mp/articles',
            method: 'GET'
        }
    }
}

// 提交文章表单API
export function getCreateArticleUrl() {
    if (envConfig.env === 'mock') {
        return {
            url: '/adarticles',
            method: 'GET'
        }
    } else {
        return {
            url: '/mp/articles?draft=false',
            method: 'POST'
        }
    }
}

// 更新文章表单API
export function getUpdateArticleUrl(data) {
    if (envConfig.env === 'mock') {
        return {
            url: '/adarticles',
            method: 'GET'
        }
    } else {
        return {
            url: `/mp/articles/${data.id}?draft=false`,
            method: 'PUT'
        }
    }
}

// 获取文章详情API
export function getArticleDetailUrl(id) {
    if (envConfig.env === 'mock') {
        return {
            url: '/articledetail',
            method: 'GET'
        }
    } else {
        return {
            url: `/mp/articles/${id}`,
            method: 'GET'
        }
    }
}

// 删除文章API
export function getDeleteArticleUrl(id) {
    if (envConfig.env === 'mock') {
        return {
            url: '/deleteArticle',
            method: 'GET'
        }
    } else {
        return {
            url: `/mp/articles/${id}`,
            method: 'DELETE'
        }
    }
}